home *** CD-ROM | disk | FTP | other *** search
- #include "DumpTracks.h"
- #include <Stdio.h>
- #include <Files.h>
- #include <Folders.h>
-
- #include <String.h>
- #include "Packages.h"
- #ifndef THINK_C
- #include <Strings.h>
- #include <Resources.h>
- #include <Memory.h>
- #include "Types.h"
- #include "Errors.h"
- #include "OSUtils.h"
- #include "StdLib.h"
- #include "ToolUtils.h"
- #endif
-
- shex gReadBuff[1024];
- shex gReadBuffSize;
- Ptr fRecordBuffer;
- char printBuff[1000];
- char *fPrintBuffer;
- char gFileName[100];
- short lastDiagID =-1;
- short gPrefsVRefNum;
- Boolean gVerboseMode =1;
-
- #ifndef THINK_C
- main(int argc, char **argv)
- #else
- main()
- #endif
- {
- snum result;
- short refNum;
- SysEnvRec Environment;
- short SysFolderRefNum;
- short PrefsResRefNum, infoFileRefNum=-1;
- Handle driverName;
-
- fRecordBuffer = (Ptr) gReadBuff;
- fPrintBuffer = printBuff;
- gReadBuffSize = sizeof(gReadBuff);
-
- (void) SysEnvirons(1, &Environment);
- SysFolderRefNum = Environment.sysVRefNum; // Get the sys folder vref
- gPrefsVRefNum = GetFolderVol(kPreferencesFolderType);
- if (gPrefsVRefNum == 0)
- {
- printf("Error finding preference folder\n");
- gPrefsVRefNum = SysFolderRefNum;
- }
-
- strcpy(gFileName,(char *)"\pTracks Prefs");
-
- #ifndef THINK_C
- ParseArgs(argc, argv);
- #endif
-
- PrefsResRefNum = OpenRFPerm(gFileName, gPrefsVRefNum, fsRdWrPerm);
- result = ResError();
- if (result != 0)
- {
- printf("Abort: prefs file get Error #%d", result);
- exit(3);
- }
-
- result = FSOpen(gFileName, 0, &refNum);
- if (result != noErr)
- {
- SetVol(nil, gPrefsVRefNum);
- result = FSOpen(gFileName,0,&refNum);
- }
-
- if (result == noErr)
- {
-
- p2cstr(gFileName);
-
- driverName = GetResource('kDRp', 128);
- if (driverName!=nil)
- {
- infoFileRefNum = OpenRFPerm(*driverName, SysFolderRefNum, fsRdWrPerm);
- if (infoFileRefNum == -1)
- infoFileRefNum = OpenRFPerm(*driverName, GetFolderVol(kExtensionFolderType), fsRdWrPerm);
- if (infoFileRefNum == -1)
- infoFileRefNum = OpenRFPerm(*driverName, GetFolderVol(kControlPanelFolderType), fsRdWrPerm);
- if (infoFileRefNum == -1)
- printf("Warning: Couldnt load name list\n");
- ReleaseResource(driverName);
- } else printf("Pref File data not found");
-
- //if (gVerboseMode)
- // printf("Dumping file %s \n", gFileName);
-
- }
-
- TypeDumpSetUp(SysFolderRefNum); // Set up template (format06) printing (reads in 'mxwt' resources)
-
- result = ReadFileRecords(refNum);
- if (result == noErr || result == eofErr)
- if (gVerboseMode) printf("\n--- End of dump ---\n");
- else
- {
- printf("--- Dump terminated, error = %d ---\n", result);
- if (result == -43) printf("(File not found)\n");
- }
-
- if (infoFileRefNum != -1)
- CloseResFile(infoFileRefNum);
- TypeDumpCloseDown();
- (void) FSClose(refNum);
- CloseResFile(PrefsResRefNum);
- exit(0);
- }
-
- short GetFolderVol(OSType type)
- {
- WDPBRec wdParamBlock; /*param block to set up working directory*/
- short result;
- short prefVRef;
- long prefDirID;
-
- result=FindFolder(kOnSystemDisk, type, true, &prefVRef, &prefDirID);
- if (result == 0)
- {
- wdParamBlock.ioCompletion = NULL;
- wdParamBlock.ioNamePtr = NULL;
- wdParamBlock.ioVRefNum = prefVRef;
- wdParamBlock.ioWDDirID = prefDirID;
- result=PBOpenWD(&wdParamBlock, false);
- if (result == 0)
- return wdParamBlock.ioVRefNum;
- }
- return 0;
- }
-
-
- void CopyEbcdicToAscii(unsigned char *ebcdic, unsigned char *toAscii,
- unsigned short dataLength)
- {
-
- unsigned char *asciiArray;
-
- // String pointer used to avoid data initialization...
-
- asciiArray = (unsigned char *)
- "\000\001\002\003\234\011\206\177"
- "\227\215\216\013\014\015\016\017"
- "\020\021\022\023\235\205\010\207"
- "\030\031\222\217\034\035\036\037"
- "\200\201\202\203\204\012\027\033"
- "\210\211\212\213\214\005\006\007"
- "\220\221\026\223\224\225\226\004"
- "\230\231\232\233\024\025\236\032"
- "\040\240\241\242\243\244\245\246"
- "\247\250\133\056\074\050\053\041"
- "\046\251\252\253\254\255\256\257"
- "\260\261\135\044\052\051\073\136"
- "\055\057\262\263\264\265\266\267"
- "\270\271\174\054\045\137\076\077"
- "\272\273\274\275\276\277\300\301"
- "\302\140\072\043\100\047\075\042"
- "\303\141\142\143\144\145\146\147"
- "\150\151\304\305\306\307\310\311"
- "\312\152\153\154\155\156\157\160"
- "\161\162\313\314\315\316\317\320"
- "\321\176\163\164\165\166\167\170"
- "\171\172\322\323\324\325\326\327"
- "\330\331\332\333\334\335\336\337"
- "\340\341\342\343\344\345\346\347"
- "\173\101\102\103\104\105\106\107"
- "\110\111\350\351\352\353\354\355"
- "\175\112\113\114\115\116\117\120"
- "\121\122\356\357\360\361\362\363"
- "\134\237\123\124\125\126\127\130"
- "\131\132\364\365\366\367\370\371"
- "\060\061\062\063\064\065\066\067"
- "\070\071\372\373\374\375\376\377";
-
-
- while (dataLength > 0)
- {
- *toAscii++ = asciiArray[(*ebcdic++)];
- dataLength--;
- }
-
- return;
-
- }
-
- CopyPStr(char *src, char *dst)
- {
- register char x,len;
- len = *src;
-
- for (x=0;x<=len;x++)
- *dst++ = *src++;
-
- }
-
- snum DecodeSym(char *stringBuffer, char *symbol, Boolean showTypeInfo, Ptr stackdataPtr)
- {
- char *funcNamePtr;
- char *classNamePtr;
- snum funcNameLength;
- snum classNameLength;
- char *typeInfoPtr;
- char *p, *copy;
- snum len;
- snum i, j;
- char *modUstr = "unsigned";
- char modUstrlen = 8;
- char *argPtr;
- char *typeNamePtr;
- char typeNameLen;
- snum typesize;
- char *argNamePtr[32];
- snum argNameLen[32];
- snum argCount;
- snum argMod[32];
- snum argSize[32];
- snum temp1;
- snum temp2;
- char tempc1;
- char tempc2;
-
-
- // function name:
-
- if (*symbol == 0)
- {
- return(0);
- }
- funcNamePtr = symbol;
- funcNameLength = 0;
-
- p = funcNamePtr;
- while ((*p != '_') && (*p != 0))
- {
- funcNameLength++;
- p++;
- }
-
- // if "__" follows the function name, then look for class name or type info
-
- classNameLength = 0;
- typeInfoPtr = NULL;
-
- if ((*p == '_') && (*(p + 1) == '_'))
- {
-
- p += 2; // skip past the "__"
-
- // if the next character is not "F", then get the class name
-
- if (*p != 'F')
- {
- len = 0;
- while ((*p <= '9') && (*p >= '0'))
- {
- if (len != 0)
- len = len * 10;
- len += *p - '0';
- p++;
- }
- classNamePtr = p;
- classNameLength = len;
- p += len;
- }
-
- // if the next character is "F", then get the type info
-
- if (*p == 'F')
- typeInfoPtr = p;
-
- }
-
-
- // TEST---
- len = 0;
- copy = stringBuffer;
- if (classNameLength > 0)
- {
- for (i = 0; i < classNameLength; i++)
- *copy++ = *(classNamePtr + i);
- *copy++ = ':';
- *copy++ = ':';
- len += 2 + classNameLength;
- }
- if (funcNameLength > 0)
- {
- for (i = 0; i < funcNameLength; i++)
- *copy++ = *(funcNamePtr + i);
- len += funcNameLength;
- }
-
- if ((typeInfoPtr != NULL) && showTypeInfo)
- {
- argPtr = typeInfoPtr + 1; // skip the "F"
-
- argCount = 0;
- if (classNameLength > 0)
- {
- argCount = 1;
- argNamePtr[0] = "this";
- argNameLen[0] = 4;
- argMod[0] = 1; // this*=
- }
- argMod[argCount] = 0;
- argNameLen[argCount] = 0;
-
- typeNamePtr = NULL;
- typeNameLen = 0;
- typesize = 0;
-
- while ((*argPtr != 0) && (argCount < 16))
- {
-
- switch (*argPtr)
- {
- case 'v' :
- typeNamePtr = "void";
- typeNameLen = 4;
- typesize = 0;
- argPtr++;
- break;
- case 'c' :
- typeNamePtr = "char";
- typeNameLen = 4;
- typesize = 4; // 4 bytes on stack ???? ( unless pascal????)
- argPtr++;
- break;
- case 's' :
- typeNamePtr = "short";
- typeNameLen = 5;
- typesize = 4; // seems to be 4 bytes on stack (unless pascal???)
- argPtr++;
- break;
- case 'i' :
- typeNamePtr = "int";
- typeNameLen = 3;
- typesize = 4;
- argPtr++;
- break;
- case 'l' :
- typeNamePtr = "long";
- typeNameLen = 4;
- typesize = 4;
- argPtr++;
- break;
- case 'e' :
- typeNamePtr = "...";
- typeNameLen = 3;
- typesize = 0;
- argPtr++;
- break;
- case 'P' :
- if ((argMod[argCount] & 1) == 0)
- argMod[argCount] |= 1; // type*
- else if ((argMod[argCount] & 2) == 0)
- argMod[argCount] |= 2; // type**
- else
- argMod[argCount] |= 16; // unknown
- argPtr++;
- break;
- case 'U' :
- argMod[argCount] |= 8; // unsigned
- argPtr++;
- break;
- case 'F' :
- if (argMod[argCount] & 1)
- {
- argMod[argCount] &= 0xfffe; // clear (type*) pointer
- argMod[argCount] |= 32; // pointer-to-function
- }
- else
- argMod[argCount] |= 16; // unknown
- argPtr++;
- break;
- case '_' :
- if (argMod[argCount] & 32) // for pointer-to-function
- {
- argMod[argCount] |= 64; // display of return value not implemented yet
- typeNamePtr = NULL;
- }
- else
- argMod[argCount] |= 16; // unknown
- argPtr++;
- break;
- case '0' :
- case '1' :
- case '2' :
- case '3' :
- case '4' :
- case '5' :
- case '6' :
- case '7' :
- case '8' :
- case '9' :
- typeNameLen = *argPtr - '0';
- if ((*(argPtr + 1) >= '0') && (*(argPtr + 1) <= '9'))
- {
- argPtr++;
- typeNameLen = 10 * typeNameLen;
- typeNameLen += *argPtr - '0';
- }
- argPtr++;
- typeNamePtr = argPtr;
- argPtr += typeNameLen;
- typesize = 4;
- break;
- case 'T' : // Tx - same as argument x
- case 'N' :
- if (*argPtr == 'N')
- {
- argPtr++;
- temp1 = *(argPtr + 1) - '0';
- }
- else
- temp1 = 1;
- argPtr++;
-
- for (i = 0; i < temp1; i++)
- {
- temp2 = *argPtr - '0';
- argPtr++;
- if (classNameLength == 0)
- temp2--; // arg n is array index n-1 (unless class "this" present)
- argNamePtr[argCount] = argNamePtr[temp2];
- argNameLen[argCount] = argNameLen[temp2];
- argMod[argCount] = argMod[temp2];
- argSize[argCount] = argSize[temp2];
- argCount++;
- argMod[argCount] = 0;
- }
- break;
- default:
- argMod[argCount] |= 16; // unknown
- argPtr++;
- break;
- }
-
- if ((typeNamePtr != NULL) &&
- (((argMod[argCount] & 32) == 0) || (*argPtr != '_')) )
- {
- argNamePtr[argCount] = typeNamePtr;
- argNameLen[argCount] = typeNameLen;
- argSize[argCount] = typesize;
- argCount++;
- argMod[argCount] = 0;
- typeNamePtr = NULL;
- typeNameLen = 0;
- }
-
- }
-
- *copy++ = '(';
- len++;
- for (i = 0; i < argCount; i++)
- {
- if (argMod[i] & 8)
- {
- for (j = 0; j < modUstrlen; j++)
- *copy++ = *(modUstr + j);
- *copy++ = ' ';
- len += (1 + modUstrlen);
- }
-
- for (j = 0; j < argNameLen[i]; j++)
- *copy++ = *(argNamePtr[i] + j);
- len += argNameLen[i];
-
- if (argMod[i] & 1)
- {
- argSize[i] = 4;
- *copy++ = '*';
- len++;
- }
- if (argMod[i] & 2)
- {
- argSize[i] = 4;
- *copy++ = '*';
- len++;
- }
- if (argMod[i] & 16)
- {
- *copy++ = '?';
- len++;
- }
- if (argMod[i] & 32)
- {
- *copy++ = ' ';
- *copy++ = '(';
- *copy++ = '*';
- *copy++ = ' ';
- *copy++ = '?';
- *copy++ = ')';
- *copy++ = '(';
- *copy++ = ')';
- len += 8;
- }
- if ((stackdataPtr != NULL) && (argSize[i] > 0))
- {
- *copy++ = '=';
- len++;
- for (j = 0; j < argSize[i]; j++)
- {
- tempc1 = (*stackdataPtr & 0xf0) >> 4;
- tempc2 = *stackdataPtr & 0x0f;
- if (tempc1 < 10)
- *copy++ = '0' + tempc1;
- else
- *copy++ = 'A' + (tempc1 - 10);
- if (tempc2 < 10)
- *copy++ = '0' + tempc2;
- else
- *copy++ = 'A' + (tempc2 - 10);
- len += 2;
- stackdataPtr++;
- }
- }
- if (i < (argCount - 1))
- {
- *copy++ = ',';
- *copy++ = ' ';
- len += 2;
- }
- }
- *copy++ = ')';
- len++;
-
- }
-
- *copy = 0; // null terminated string
-
-
-
- return(len);
-
- }
-
-
- DumpBytes(Ptr p, short s)
- {
- int i;
- Ptr addr;
-
- addr = p;
- for (i = 0; i < s; i++)
- {
- if (i % 32 == 0)
- printf("%08x: ", p - addr);
-
- printf("%02x", *p++ & 0x0ff);
-
- if (i % 4 == 3)
- printf(" ");
-
- if (i % 32 == 31)
- printf("\n");
- }
- if (i % 32 != 0)
- printf("\n");
- }
-
- #ifndef THINK_C
- void ParseArgs(int argc, char **argv)
- {
- char type;
- char *arg;
- /*------- Get command line arguments ----------------*/
-
- type = ' ';
- for (argv++, argc--; argc--; argv++) /* skip av[0] */
- {
- arg = (char *) *argv;
-
- type = (arg[0] == '-') ? (char) arg[1] : type;
- if (arg[0] == '-')
- arg += 2;
-
- switch (type)
-
- {
- case 'f' : /* set the tracefile name */
- if (*arg == 0)
- break;
- (void) strcpy(gFileName, arg);
- c2pstr(gFileName);
- break;
-
- case ' ':
- break;
- case 'q' : gVerboseMode = false;
- break;
- default:
- (void) printf("DumpTracks: illegal option [%c]\n", (char) type);
- (void) printf("format DumpTracks [ -f tracefilename] [-q] \n");
- exit(3);
-
- }
- }
-
- return;
-
- }
- #endif
-
- // Prints StackPeek data
- void PrintFmt01(char *fmt01Ptr)
- {
- char *stackdata;
- char *modulesym;
- char *callersym;
- snum modulelen;
- snum callerlen;
- char symbolName[256];
- char module[256], caller[256];
-
-
- stackdata = fmt01Ptr;
- modulesym = SkipPStr(stackdata);
- callersym = SkipPStr(modulesym);
-
- CopyPStr(modulesym, module);
- CopyPStr(callersym, caller);
-
- p2cstr(module);
- p2cstr(caller);
-
- modulelen = *modulesym;
- callerlen = *callersym;
-
- // if (0 ) printf("Decoding '%s' and '%s', %d, %d\n", module, caller, strlen(module), strlen(caller));
-
- (void) DecodeSym(symbolName, module, true, (Ptr) stackdata + 8);
-
- printf("'%s'\n", symbolName);
-
- (void) DecodeSym(symbolName, caller, true, (Ptr) stackdata + 8);
-
- printf(" called by '%s'\n", symbolName);
-
- return;
- }
-
-
-
- void PrintFmt02(Ptr dataPtr, short dataLength)
- {
- int i;
- unsigned char ascii[18];
- unsigned char ebcdic[18];
- unsigned char c;
- BytePtr p;
- int pos;
- int linelen;
- int prtlen;
-
-
- // Get length from LL field (length of print data does not include 2 bytes of LL)
-
- prtlen = dataLength;
-
- p = (BytePtr)dataPtr;
- pos = 0;
-
- /* Here is a sample output line to line up the header text: */
- /******"(00: 0000 0000 0D4C 4F4B 4920 5761 7220 524F ……………LOKI War RO IIIII<!.®ÄØ/ºÄ™! ****/
- printf("\n");
-
- #ifdef PRINTEBCIDIC
- printf(" ---- ASCII ----- ---- EBCDIC ----\n");
- #else
- printf(" ---- ASCII -----\n");
- #endif
-
- while (prtlen > 0)
- {
-
- printf("%02X: ", (pos & 0x0ff));
-
- linelen = 16;
- if (linelen > prtlen)
- linelen = prtlen;
-
- for (i = 0; i < linelen; i++)
- {
- c = *p++;
- pos++;
- if ((c < 0x20) || (c == 0x7f)) // normally nonprinting characters
- ascii[i] = '.';
- else
- ascii[i] = c;
-
- printf("%02X", c);
-
- if ((i == 7) || (i == 15))
- printf(" ");
- else if ((i% 2) == 1)
- printf(" ");
-
- }
- for (i = linelen; i < 16; i++)
- {
- printf(" ");
- if ((i == 7) || (i == 15))
- printf(" ");
- else if ((i% 2) == 1)
- printf(" ");
- }
-
- CopyEbcdicToAscii(ascii, ebcdic, linelen);
- ascii[linelen] = ' ';
- ebcdic[linelen] = ' ';
- for (i = (linelen + 1); i < 17; i++)
- {
- ascii[i] = ' ';
- ebcdic[i] = ' ';
- }
- ascii[17] = 0;
- ebcdic[17] = 0;
- #ifdef PRINTEBCIDIC
- printf(" %s %s\n", ascii, ebcdic);
- #else
- printf(" %s\n", ascii);
- #endif
- prtlen -= linelen;
-
- }
-
- return;
-
- }
-
-
- void PrintFmt04(long dataLong)
- {
- char data1, data2, data3, data4;
- data1 = (dataLong >> 24) & 0x0ff;
- if ((data1 < 0x20) || (data1 == 0x7f)) // normally nonprinting characters
- data1 = '.';
- data2 = (dataLong >> 16) & 0x0ff;
- if ((data2 < 0x20) || (data2 == 0x7f)) // normally nonprinting characters
- data2 = '.';
- data3 = (dataLong >> 8) & 0x0ff;
- if ((data3 < 0x20) || (data3 == 0x7f)) // normally nonprinting characters
- data3 = '.';
- data4 = dataLong & 0x0ff;
- if ((data4 < 0x20) || (data4 == 0x7f)) // normally nonprinting characters
- data4 = '.';
- printf("DATA = 0x%08X #%d '%c%c%c%c'\n",
- dataLong, dataLong, data1, data2, data3, data4);
- }
-
- // Format of data is:
- // Length long word + Data [length bytes]
- void PrintFmt05(BytePtr data)
- {
- long *dataLong;
-
- dataLong = (long *)data;
- data += 4; // skip past the long
- p2cstr(data);
- printf("'%s' %-5ld 0x%-8lX\n",
- data, *dataLong, *dataLong);
- c2pstr(data);
- // PrintFmt04(*dataLong);
- }
-
- // Format of dataPtr is
- // Length long [], Data [length bytes], PStr [Type Name]
-
- void PrintFmt06(BytePtr data)
- {
- BytePtr typeStr, result;
- long *length;
- long extraData;
-
- length = (long *)data;
- data += 4; // skip past the long
- typeStr = data + *length;
-
- result = PrettyDump(data, typeStr);
- extraData = (long)result - (long)typeStr;
-
-
- if (result == nil)
- {
- // printf("Data Type Not Found. Printing as data\n");
- PrintFmt02(data, *length);
- }
- else
- if (extraData < 0)
- {
- printf("••• Not enough data sent. Some data is invalid •••\n");
- }
-
- else
- if (result-typeStr > 0)
- {
- printf("Dumping extra data...\n");
- PrintFmt02(result, extraData);
- }
- // Check here later for extra data appended... (that didn't fit in the record)
- }
-
-
- void PrintRecord(snum length)
- {
- register NewRecordTemplate *template;
- long dataLong;
- Str255 maskName;
- BytePtr dataStart;
-
- if (length >= 4)
- {
- template = (NewRecordTemplate *)gReadBuff;
- #ifdef TEST
- printf("template->length %d\n", template->length);
- printf("template->diagID %d\n", (short) template->diagID);
- printf("template->partCode %d\n", (short) template->partCode);
- printf("template->formatID %d\n", (short) template->formatID);
- // printf("template->timestamp %ld\n", template->timeStamp );
- #endif
-
- GetIndString(maskName, kMaskStringListID, (template->diagID & 0x7F) + 1);// Get String list name.
- // +1 because mask numbers start at 0, str#'s start at 1
-
- //
- // Either DiagID is out of range or it is a new trace DiagID that has
- // not been added to the STR# resource in cdev.r
- //
- if (maskName[0] == 0) // Perhaps out of range or STR# list not there...
- strcpy((char *)maskName,(char *)"\p ???");
-
- if (template->partCode == 0)
- {
- lastDiagID = template->diagID;
- p2cstr(maskName);
- if (gVerboseMode) printf("\n++ Trace Record ");
- if (!gVerboseMode) printf("\n\n");
- if (gVerboseMode) PrintTimeAndDate(template->timeStamp);
- if (gVerboseMode) printf(" ++\n++ DiagID %02d ( %s ) ++\n", template->diagID, maskName);
- if (0) printf("Format ID = %d\n", (short) template->formatID);
- }
- else
- if (template->diagID != lastDiagID) // First partCode must be zero
- printf(" ••• Trace partCode 0 expected •••\n");
-
- if (gVerboseMode) printf("(%3d-%2d) ",(short) template->diagID & 0x7f,(short)template->partCode & 0x7f);
-
- dataStart = (BytePtr)template;
- dataStart += sizeof(template);
-
- dataStart = &template->formatID;
- dataStart++;
-
- switch (template->formatID)
- {
- case 0x00:
- printf("••• Data Lost Record •••\n");
- break;
- case 0x01:
- if (gVerboseMode) printf("STACKPEEK\n");
- PrintFmt01(dataStart);
- break;
-
- case 0x02:
- if (gVerboseMode) printf("DATA ");
- // Length of Template --- sizeof(template) -2 -- was 12 prior..
- PrintFmt02(dataStart, template->length - 10); // 10 = Length of template!
- break;
-
- case 0x03:
- {
- char *bytePtr;
- bytePtr = dataStart;
- // bytePtr++;
- if (gVerboseMode) printf("PSTR \n");
-
- p2cstr(bytePtr);
- printf("\"%s\"\n", bytePtr);
- c2pstr(bytePtr);
- }
- break;
-
- case 0x04:
- if (gVerboseMode) printf("LONG \n");
- dataLong = *(long *)dataStart;
- PrintFmt04(dataLong);
- break;
-
- case 0x05:
- if (gVerboseMode) printf("PSTR + LONG \n");
- PrintFmt05(dataStart);
- break;
-
- case 0x06:
- if (gVerboseMode) printf("FORMATTED TYPE DUMP\n");
- PrintFmt06(dataStart);
- break;
-
- default:
- printf("•••• Unknown FormatID %d ••••\n", (short)template->formatID);
- break;
- }
-
- // printf("\n"); // Space in between part codes....
- }
-
- return;
-
- }
-
- void PrintTimeAndDate(long timestamp)
- {
- Str31 dateStr,timeStr;
- IUDateString(timestamp, abbrevDate, dateStr);
- p2cstr(dateStr);
- IUTimeString(timestamp, true, timeStr);
- p2cstr(timeStr);
- printf("%s at %s",timeStr,dateStr);
- }
-
-
- snum ReadFileRecords(short refNum)
- {
- snum result;
- shex recordSize; // Size of the current trace record being read
- long readAmount; // Number of bytes to read from file
- long lostAmount; // Number of bytes of record that will not fit in buffer
- Boolean gotLength; // true if we read the length field
-
- // While no errors, retrieve trace records...
-
- result = 0;
-
- while (result == noErr)
- {
-
- // Read in the record length field (2 bytes):
-
- gotLength = false;
-
- readAmount = 2;
- result = FSRead(refNum, &readAmount, (Ptr) gReadBuff);
-
- if ((result == noErr) && (readAmount != 2))
- result = paramErr; // use this error to flag this unexpected condition
- else
- {
- gotLength = true;
-
- // Read in the remainder of this record:
- // (Do not read in more than the buffer will hold)
-
- recordSize = *((shex *) gReadBuff);
- readAmount = recordSize - 2;
-
- if (readAmount > gReadBuffSize)
- {
- lostAmount = readAmount - gReadBuffSize;
- readAmount = gReadBuffSize;
- }
- else
- lostAmount = 0;
-
- result = FSRead(refNum, &readAmount, ((Ptr) gReadBuff) + 2);
-
- // If the trace record was too big for the buffer, move file mark past
- // the end of this record so the next read will get th next record...
-
- if ((result == noErr) && (lostAmount != 0))
- result = SetFPos(refNum, fsFromMark, lostAmount);
-
- // Print this record:
-
- if (result == noErr)
- PrintRecord(readAmount + 2);
-
- }
- }
-
- // If the error was end-of-file reached while reading length, then return noErr
-
- if ((result == eofErr) && ! gotLength)
- result == noErr;
-
- return(result);
-
- }
-
- Str31 gKnownTypeList[] = {"\pByte", "\pWord", "\pLong", "\pSignedByte", "\pSignedWord", "\pSignedLong",
- "\pUnsignedByte", "\pUnsignedWord", "\pUnsignedLong", "\pBoolean", "\ppString", "\pcString",
- "\pText", "\pSkip", "\pAlign", "\pHandle", "\pPointer"};
-
- enum {kByte, kWord, kLong, kSignedByte, kSignedWord, kSignedLong, kUnsignedByte, kUnsignedWord, kUnsignedLong, kBoolean, kpString,
- kcString, kText, kSkip, kAlign, kHandle, kPointer, kNumTypes};
-
-
-
- BytePtr gDataPtr;
- short gNumResources;
- TmplHandle gDataHandle[10];
-
-
- BytePtr SkipPStr(BytePtr str)
- {
- short num, x;
- num = (short) *str;
- str++;
- for (x=0;x<num;x++)
- str++;
- return (str);
- }
-
-
- // Note: gKnownTypeList is defined above, and contains a list of the basic
- // type definitions, such as Long, Boolean, etc...
- BytePtr DumpMemory (BytePtr wh, char *type)
- {
- short x;
- long *lp;
- short *sp;
- lp = (long *)wh;
- sp = (short *)wh;
-
- if (wh == nil) {printf("DumpMemory err: data ptr = nil\n");return nil;}
-
- x = -1;
-
- if (type[1] == '^') x = kPointer;
- if (type[2] == '^') x = kHandle;
-
- if (x == -1) // if not a pointer (^xxx) or handle (^^dataBlock)
- {
- for (x=0;x<kNumTypes;x++)
- if (strcmp(type, (char *)gKnownTypeList[x]) == 0) break;
- }
-
- switch (x)
- {
- case kByte:
- case kSignedByte:
- printf("%-02d ", *wh);wh+=1;break;
- case kWord:
- case kSignedWord:
- printf("%-6d ", *sp);wh+=2;break;
- case kSignedLong:
- case kLong:
- printf("%-08ld ", *lp);wh+=4;break;
- case kUnsignedByte:
- printf("0x%-02X = '%c'", *wh, *wh);wh+=1;break;
- case kUnsignedWord:
- printf("0x%-6X ", *sp);wh+=2;break;
- case kUnsignedLong:
- printf("0x%-08ld ", *lp);wh+=4;break;
- case kBoolean:
- if (*wh)
- printf("true ");
- else
- printf("false ");
- wh+=1;break; // Check this...
-
- case kpString:
- {
- short len = *wh,c;
-
- wh++;
- printf("pString = '");
- for (c=0;c<len;c++)
- printf("%c", *wh++);
- printf("'");
- break;
- }
- case kcString:
- {
- printf("cString = '");
- while (*wh)
- printf("%c", *wh++);
- printf("'");
- break;
- }
-
- case kText: break; // Not supported...
-
- case kSkip:
- printf("0x%-4X", *sp);
- wh+=2;
- break;
-
- case kAlign:
- printf("ALIGN byte (%d)", *wh);
- wh++;break;
-
- case kHandle:
- printf("0x%-08lX ", *lp);wh+=4;break;
-
- case kPointer:
- printf("0x%-08lX ", *lp);wh+=4;break;
-
- case kNumTypes: // Specified template was not of standard type....
- if (0)
- {
- p2cstr(type);
- printf("Looking for type '%s'\n", type);
- c2pstr(type);
- }
- wh = DMWithTemplate(wh, type);
- break;
- default :
- p2cstr(type);
- printf("DT Err: Unknown type: '%s'\n", type);
- c2pstr(type);
- break;
- };
- return wh;
- }
-
-
- // Displays info on template, and points to the next one
- BytePtr HandleField(BytePtr field, Boolean printOn)
- {
- short *count, r;
- char *fieldName, *type;
-
- if (printOn) printf(" '");
- fieldName = field;
- if (printOn) PrintPStr(fieldName);
- field = SkipPStr(field);
- if (printOn) printf("' ");
-
- type = field;
- field = SkipPStr(field);
-
- // if (printOn) (void) PrintPStr(type);
- // if (printOn) printf (" ");
- count = (short *) field;
-
-
- field += 2;
-
- if (printOn)
- for (r = 0; r < *count; r++)
- {
- if (gDataPtr == nil) printf("Type dump err..\n"); // doesnt happen
- gDataPtr = DumpMemory(gDataPtr, type); // Call recursivly
- if (gDataPtr == nil) {printf("DumpMemory Error\n");break;}
- }
- if (printOn) printf("\n");
- return field;
- }
-
- // Displays info on template, and points to the next one
- BytePtr HandleTemplate(BytePtr tmpl, Boolean printOn)
- {
- short x, *fields;
- char *templateName;
-
- templateName = tmpl;
- tmpl = (char *) SkipPStr(tmpl);
-
- if (printOn)
- {
- (void) PrintPStr(templateName); // Special Type Name
- printf("\n");
- }
- fields = (short*) tmpl;
- tmpl += 2;
-
- // I assume there will be no data structrures with more than 100 fields...
- if (*fields > 100) {printf("Type Dump Error. %d is too many fields (>100) \n", *fields);return nil;}
-
- for (x=0;x < *fields;x++)
- tmpl = HandleField(tmpl, printOn);
- return tmpl; // this now points to the next template...
- }
-
-
- short TypeDumpSetUp(short SysFolderRefNum)
- {
- short x;
- short err;
- short prefsResRefNum;
-
- prefsResRefNum = OpenRFPerm("\pDebugger Prefs", SysFolderRefNum, fsRdWrPerm);
- err = ResError();
- if (err != noErr) prefsResRefNum = 0;
- gNumResources = CountResources('mxwt');
- if (gNumResources >10) gNumResources = 10; /* Heaven forbid they have more... */
-
- if (gNumResources > 0)
- for (x=0;x<gNumResources;x++)
- {
- gDataHandle[x] = (TmplHandle)GetIndResource('mxwt', x+1);
-
- // if (gDataHandle) printf("Loaded mxwt resource\n");
-
- if (gDataHandle[x] == nil) {printf("Failed to load resource\n");gNumResources = x-1;return false;}
- DetachResource((Handle)gDataHandle[x]);
- HLock((Handle)gDataHandle[x]);
- }
- if (prefsResRefNum)
- CloseResFile(prefsResRefNum);
- return x;
- }
-
- void TypeDumpCloseDown()
- {
- short x;
- for (x=0;x<gNumResources;x++)
- {
- HUnlock((Handle)gDataHandle[x]);
- DisposHandle((Handle)gDataHandle[x]);
- gDataHandle[x] = nil;
- }
- }
-
- ComparePStr(char *a, char *b)
- {
- char len, x;
- len = *a;
- for (x=0;x<=len;x++)
- if (*a++ != *b++) return false;
- return true;
- }
-
-
- BytePtr DMWithTemplate (BytePtr wh, char *searchType)
- {
- short numTemplates;
- short x, t;
- BytePtr tmpl;
- Boolean PrintRecord;
-
- gDataPtr = wh;
- for (t=0;t<gNumResources;t++)
- {
- numTemplates = (**gDataHandle[t]).NumTemplates;
- tmpl = (BytePtr) &(**gDataHandle[t]).FirstTemplate;
-
- for (x=0;x < numTemplates;x++) // numTemplates
- {
- PrintRecord = ComparePStr(searchType, tmpl); /* Is this it? If so, print it out.. */
- tmpl = HandleTemplate(tmpl, PrintRecord);
- if (PrintRecord) return gDataPtr;
- }
- }
- return nil;
- }
-
- BytePtr PrintPStr(BytePtr str)
- {
- register short num, x, i;
- num = (short) *str;
- str++;
- for (x=0;x<num;x++)
- printf("%c", *str++);
- for (i=x;i< 17;i++)
- printf(" ");
- return (str);
- }
-
- BytePtr PrettyDump(BytePtr data, BytePtr typeString)
- {
- BytePtr found;
- found = DumpMemory((BytePtr)data, typeString);
- if (found == nil)
- {
- p2cstr(typeString);
- printf("'%s' Unknown Data Type.", typeString);
- c2pstr(typeString);
- }
- printf("\n");
- return found;
- }
-
-